package com.sugon.dao;

import com.sugon.entity.ErpSpTransactionEntity;
import com.sugon.entity.SparePartDeliveryRecord;
import com.sugon.entity.SparePartInEntity;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * 入库记录Dao
 *
 * @author sugon
 * @date 2019-07-12 08:50:22
 */
public interface SparePartInDao extends BaseDao<SparePartInEntity> {

    @Select("SELECT ITEM_CODE FROM EMS_CUX_MFG_ERMS_FDJ_TXN_INFO WHERE TRANSACTION_ID = ${transactionId}")
    ErpSpTransactionEntity queryByTransactionId(@Param("transactionId") Long transactionId);

    /**
     * 查看指定备件所有入库记录中已关联ERP入库记录
     *
     * @param partCode 备件编码
     * @return
     */
    @Select("SELECT * FROM SPARE_PART_IN WHERE PART_CODE = #{partCode} AND ERP_INBOUND_RECORD_ID IS NOT NULL")
    List<SparePartInEntity> listErpInboundRecord(@Param("partCode") String partCode);

    /**
     * 条件查询总记录数
     *
     * @return
     */
    int queryErpInboundTotal(Map<String, Object> map);

    /**
     * 查询总列表
     *
     * @param map
     * @return
     */
    List<ErpSpTransactionEntity> queryErpInboundList(Map<String, Object> map);

    /**
     * 统计某一库位中某个月份下的出库总数
     *
     * @param posId 库位ID
     * @param month 月份字符串
     * @return
     */
    Integer statTotalNum(@Param("posId") String posId, @Param("month") String month);

    /**
     * 获取指定编码前缀的入库编码
     */
    String getLastestPartCode(@Param("codePrefix") String codePrefix);

    /**
     * 保存备件到货记录
     *
     * @param deliveryRecord
     * @return
     */
    int saveDeliveryRecord(SparePartDeliveryRecord deliveryRecord);

}
